package com.zcf.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zcf.common.yunos.aliyun.MessageType;
import com.zcf.common.yunos.aliyun.SendMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.alipay.api.AlipayApiException;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.zcf.common.json.Body;
import com.zcf.common.utils.MD5Util;
import com.zcf.mapper.UserMapper;
import com.zcf.pojo.Astrict;
import com.zcf.pojo.Code;
import com.zcf.pojo.Dining;
import com.zcf.pojo.Log;
import com.zcf.pojo.Orderinfo;
import com.zcf.pojo.Percentage;
import com.zcf.pojo.Riding;
import com.zcf.pojo.Subordinate;
import com.zcf.pojo.User;
import com.zcf.service.UserService;
import com.zcf.utils.Hutool;
import com.zcf.utils.UploadImgUtils;
import com.zcf.utils.sendsms;
import com.zcf.utils.zhifubao.Query;
import com.zcf.utils.zhifubao.transfer;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zhouzhuang
 * @since 2018-11-28
 */
@Controller
@RequestMapping("/user")
@CrossOrigin
@ResponseBody
public class UserController {
    @Autowired
    private UserService userService;
    @Autowired
    private UserMapper userMapper;

    /**
     * 微信登陆（注册）
     *
     * @param name
     * @param wx_id
     * @param head
     * @return
     */
    @PostMapping("oppidlogin")
    public Body oppidlogin(String wx_id, String name, String head) {
        name = Hutool.getId();
        System.out.println(wx_id + "!!!!!!!" + name + "!!!!!" + head);
        return userService.login(wx_id, name, head);
    }

    // 用户注册
    @PostMapping("/register")
    public Body register(String phone, String password, String code) {
        if (password != null && !"".equals(password)) {
            return userService.register(phone, password, code);
        }
        return Body.newInstance(501, "请输入手机号或者验证码");
    }

    // 用户登录
    @PostMapping("/login")
    public Body login(String phone, String password) {
        return userService.login(phone, password);
    }

    // 忘記密碼
    @PostMapping("/forgetPassword")
    public Body forgetPassword(String phone, String newPassword, String code) {
        return userService.forgetPassword(phone, newPassword, code);
    }

    // 变为骑手
    @PostMapping("/changeRiding")
    public Body changeRiding(String userId) {
        User user = new User();
        EntityWrapper<User> ew = new EntityWrapper<User>();
        ew.eq("user_id", userId);
        User one = user.selectOne(ew);
        one.setStatus(1);
        boolean b = one.updateById();
        if (b) {
            return Body.newInstance(one);
        }
        return Body.newInstance(501, "操作失败");
    }

    // 变为商家
    @PostMapping("/changeStore")
    public Body changeStore(String userId) {
        User user = new User();
        EntityWrapper<User> ew = new EntityWrapper<User>();
        ew.eq("user_id", userId);
        User one = user.selectOne(ew);
        one.setStatus(2);
        boolean b = one.updateById();
        if (b) {
            return Body.newInstance(one);
        }
        return Body.newInstance(501, "操作失败");
    }

    // 变为用户
    @PostMapping("/changeShop")
    public Body changeShop(String userId) {
        User user = new User();
        EntityWrapper<User> ew = new EntityWrapper<User>();
        ew.eq("user_id", userId);
        User one = user.selectOne(ew);
        one.setStatus(0);
        boolean b = one.updateById();
        if (b) {
            return Body.newInstance(one);
        }
        return Body.newInstance(501, "操作失败");
    }

    // 查看用户列表
    @PostMapping("/checkUserList")
    public Body checkUserList() {
        List<User> list = userMapper.checkUserList();
        if (!list.isEmpty()) {
            return Body.newInstance(list);
        }
        return Body.newInstance(501, "没有用户");
    }

    // 修改头像
    @PostMapping("/changeHead")
    public Body changeHead(String userId, MultipartFile[] file) {
        try {
            String heard = UploadImgUtils.uploadFiles(file);
            User user = new User();
            EntityWrapper<User> ew = new EntityWrapper<User>();
            ew.eq("user_id", userId);
            User one = user.selectOne(ew);
            one.setHead(heard);
            boolean b = one.updateById();
            if (b) {
                return Body.newInstance(one);
            }
            return Body.newInstance(501, "上传有误");
        } catch (Exception e) {
            e.printStackTrace();
            return Body.newInstance(501, "上传报错");
        }

    }

    /**
     * 修改用户名
     */
    @PostMapping("updateName")
    public Body updateName(String id, String name) {
        User user = new User();
        user.setId(id);
        user = user.selectById();
        if (user == null) {
            return Body.newInstance("用户不存在");
        }
        user.setName(name);
        Boolean flag = user.updateById();
        if (flag) {
            return Body.newInstance(user);
        }
        return Body.BODY_500;
    }

    @PostMapping("updateImg")
    public Body updateImg(String id, String img) {
        User user = new User();
        user.setId(id);
        user = user.selectById();
        if (user == null) {
            return Body.newInstance("用户不存在");
        }
        user.setHead(img);
        Boolean flag = user.updateById();
        if (flag) {
            return Body.newInstance(user);
        }
        return Body.BODY_500;
    }

    // 修改名称
    @PostMapping("/changeName")
    public Body changeName(String userId, String name, String img, String cid) {
        User user = new User();
        EntityWrapper<User> ew = new EntityWrapper<User>();
        ew.eq("id", userId);
        User one = user.selectOne(ew);
        if (name != null) {
            one.setName(name);
        }
        if (img != null) {
            one.setHead(img);
        }
        if (cid != null) {
            one.setCid(cid);
        }
        boolean b = one.updateById();
        if (b) {
            return Body.newInstance(one);
        }
        return Body.newInstance(501, "上传有误");
    }

    // 修改手机号
    @PostMapping("/changePhone")
    public Body changePhone(String phone, String newPhone, String code) {
        return userService.changePhone(phone, newPhone, code);
    }

    // 修改密码
    @PostMapping("/changePassword")
    public Body changePassword(String userId, String phone, String password, String newPassword) {
        return userService.changePassword(userId, phone, password, newPassword);
    }

    /**
     * 发送短信
     */
    @PostMapping("sendsmsLp")
    public Body sendsmsLp(String phone) {
        sendsms sd = new sendsms();
//		int sum = sd.send(phone);
        int mobile_code = (int) ((Math.random() * 9 + 1) * 100000);
        String random = mobile_code + "";
        SendMessage.send(MessageType.REGISTER, phone, random);

        if (mobile_code != 0) {
            Code code = new Code();
            code.setCode(mobile_code + "");
            code.insert();
            return Body.newInstance(mobile_code);
        }
        return Body.newInstance(-1, "发送失败");
    }

    /**
     * 查询用户信息
     */
    @PostMapping("queryUser")
    public Body queryUser(String id) {
        User user = new User();
        EntityWrapper<User> wrapper = new EntityWrapper<>();
        wrapper.eq("id", id);
        user = user.selectOne(wrapper);
        if (user != null) {
            return Body.newInstance(user);
        }
        return Body.BODY_500;
    }

    /**
     * 添加地区代理
     */
    @PostMapping("insertDaiLi")
    public Body insertDaiLi(User user) {

//		String filename = user.getAddress();
//		String levelCode = filename.substring(filename.indexOf("省") + 1).trim();// 逗号后面
//		String levelCodes = levelCode.substring(0, levelCode.indexOf("市") + 1).trim();// 逗号前面
//		System.err.println(levelCodes);
        user.setId(Hutool.getId());
        user.setPassword(MD5Util.MD5EncodeUtf8(user.getPassword()));
        user.setTime(Hutool.parseDateToString());
        Boolean falg = user.insert();
        if (falg) {
            return Body.BODY_200;
        }
        return Body.BODY_500;
    }

    /**
     * 修改用户
     */
    @PostMapping("update")
    public Body update(User user) {
        Boolean falg = user.updateById();
        if (falg) {
            return Body.newInstance("修改成功");
        }
        return Body.newInstance("修改");
    }

    /**
     * 微信退款
     *
     * @throws Exception
     */
    @PostMapping("weixinTukuan")
    public Body weixinTukuan(HttpServletRequest request, HttpServletResponse response, Orderinfo order, String price)
            throws Exception {
        WXpayController wXpayController = new WXpayController();
//		price = order.getTotalMoney() + "";
        Integer count = AliAndWXRefund.wxRefund(order.getTotalMoney(), order.getOrderInfoId());
        if (count > 0) {
            return Body.newInstance("退款成功");
        }
        return Body.newInstance("退款失败");
    }

    /**
     * 微信、支付宝退款
     *
     * @param id == orderId
     * @return
     * @throws Exception
     */
    @PostMapping("zhifubaoTuikuan")
    public Body zhifubaoTuikuan(String id, String userId, Orderinfo order, String prices) throws Exception {
        id = order.getOrderInfoId();
        Orderinfo orderinfo = new Orderinfo();
        orderinfo.setOrderInfoId(order.getOrderInfoId());
        orderinfo = orderinfo.selectById();
        if (orderinfo.selectById() == null) {
            return Body.newInstance("订单不存在");
        }
        orderinfo = orderinfo.selectById();
        if (orderinfo.getDinStatus() != 0) {
            return Body.newInstance("商家或骑手已经接单,不能退款");
        }

        Boolean flag = false;
        if (orderinfo.getPayment().equals("1")) {
            Double money = 0.0;
//            if (orderinfo.getCouponMoney() != null) {
//                money = orderinfo.getTotalMoney() - Double.parseDouble(orderinfo.getCouponMoney());
//            }
            money = orderinfo.getTotalMoney();// - Double.parseDouble(orderinfo.getCouponMoney());
            prices = money + "";
            Integer count = AliAndWXRefund.wxRefund(money, orderinfo.getOrderNumber());
            if (count == 1) {
                Orderinfo orderinfo2 = new Orderinfo();
                orderinfo2.setStatus(4);
                orderinfo2.setDinStatus(6);// 退款
                orderinfo2.setOrderInfoId(order.getOrderInfoId());
                orderinfo2.updateById();

                User user = new User();
                user.setId(userId);
                user.selectById();
                Log log = new Log();
                log.setLogId(Hutool.getId());
                log.setAddtime(Hutool.parseDateToString());
                log.setMoneys(money + "");
                log.setLogDesc("微信退款");
                log.setLogType(1);
                log.setLogName(user.getName() + ":微信退款" + money + "元");
                log.insert();
                return Body.newInstance("退款成功");
            }
            return Body.newInstance("退款失败");
        } else {
            Double money = 0.0;
//            if (orderinfo.getCouponMoney() != null) {
                money = orderinfo.getTotalMoney() ;//- Double.parseDouble(orderinfo.getCouponMoney());
//            }
            flag = Query.refundMoney(orderinfo.getOrderNumber(), money);
            if (flag) {
                Orderinfo orderinfo2 = new Orderinfo();
                orderinfo2.setStatus(4);
                orderinfo2.setDinStatus(6);// 退款
                orderinfo2.setOrderInfoId(order.getOrderInfoId());
                orderinfo2.updateById();

                User user = new User();
                user.setId(userId);
                user.selectById();
                if (user != null) {
                    Log log = new Log();
                    log.setLogId(Hutool.getId());
                    log.setAddtime(Hutool.parseDateToString());
                    log.setMoneys(money + "");
                    log.setLogDesc("ZFBTK");
                    log.setLogType(1);
                    log.setLogName(user.getName() + ":支付宝退款" + money + "元");
                    log.insert();
                }
                return Body.newInstance("退款成功");
            }
            return Body.newInstance("退款失败");
        }
    }

    /**
     * 支付宝提现
     */
    @SuppressWarnings("null")
    @PostMapping("ZhifubaoTiXian")
    public Body ZhifubaoTiXian(String userId, String realname, Double money, String payZhifu, String bank) {
        User user = new User();
        user.setId(userId);
        user = user.selectById();
        if (user == null) {
            return Body.newInstance("用户不存在");
        }
        if (user.getMoney() < money) {
            return Body.newInstance("提现金额大于账户余额");
        }
//        if (payZhifu == null || payZhifu.equals("")) {
//            return Body.newInstance(-1, "请绑定支付宝账号");
//        }

        if (money < 0.1) {
            return Body.newInstance(-2, "提现金额不能小于0.1元");
        }
        Astrict astrict = new Astrict();
        astrict.setAstrictId("2019EW02284W1416n550");
        astrict = astrict.selectById();
        if (astrict != null) {
            if (user.getStatus() == 2) {
                if (money < astrict.getAstrictDinMinimum()) {
                    return Body.newInstance("提现金额不能小于:" + astrict.getAstrictDinMinimum() + "元");
                } else {
                    //money = money - astrict.getAstrictDinCommission();
                }
            } else if (user.getStatus() == 1) {
                if (money < astrict.getAstrictRinMinimum()) {
                    return Body.newInstance("提现金额不能小于:" + astrict.getAstrictRinMinimum() + "元");
                } else {
                    //money =money - astrict.getAstrictDinCommission();
                }
            }
        }
//		transfer transfer = new transfer();
        if (bank.equals(null) || bank.equals("")) {

            String payZhifu2 = user.getPayZhifu2();
//            int sum = 0;
//            try {
//                sum = transfer.AlipayFundTransToaccountTransfer("", money, payZhifu, payZhifu2);
//            } catch (AlipayApiException e) {
//                e.printStackTrace();
//            }
           // System.err.println(sum);
            int sum = 1;
            if (sum == 1) {
                user.setMoney(user.getMoney() - money);
                user.updateById();
                Log log = new Log();
                log.setLogId(Hutool.getId());
                log.setAddtime(Hutool.parseDateToString());
                log.setMoneys(money + "");
                log.setLogDesc("支付宝提现：支付宝账号："+payZhifu2);
                log.setLogType(2);
                log.setUserId(user.getId());
                log.setLogName(user.getName() + ":支付宝提现" + money + "元");
                log.insert();
                return Body.newInstance("提现成功");
            }
        } else {
            user.setMoney(user.getMoney() - money);
            user.updateById();
            Log log = new Log();
            log.setLogId(Hutool.getId());
            log.setAddtime(Hutool.parseDateToString());
            log.setMoneys(money + "");
            log.setLogDesc("银行卡提现：银行卡账号："+bank);//+"姓名"+user.getName());
            log.setLogType(2);
            log.setUserId(user.getId());
            log.setLogName(user.getName() + ":银行卡提现" + money + "元");
            log.insert();
            return Body.newInstance("银行卡提现成功");
        }
        return Body.newInstance("提现失败");
    }

    /**
     * 查询用户
     */
    @PostMapping("queryAll")
    public Body queryAll(User user) {
        EntityWrapper<User> ew = new EntityWrapper<>();
        if (user.getName() != null) {
            ew.like("name", user.getName());
        }
        if (user.getPhone() != null) {
            ew.like("phone", user.getPhone());
        }
        List<User> list = user.selectList(ew);
        List<User> lists = new ArrayList<>();
        for (User user2 : list) {
            if (user2.getRole() == 0) {
                if (user2.getRole() == 1) {
                    user2.setUserRoole("管理员");
                }
                if (user2.getRole() == 0) {
                    user2.setUserRoole("普通用户");
                }
                if (user2.getRole() == 3) {
                    user2.setUserRoole("地区代理");
                }
                if (user2.getStatus() == 0) {
                    user2.setUserStatus("用户");
                }
                if (user2.getStatus() == 2) {
                    user2.setUserStatus("商家");
                }
                if (user2.getStatus() == 1) {
                    user2.setUserStatus("骑手");
                }
                lists.add(user2);
            }
        }
        if (lists.size() > 0) {
            return Body.newInstance(lists);
        }
        return Body.BODY_500;
    }

    /**
     * 删除用户
     */
    @PostMapping("deleteUserAll")
    public Body deleteUserAll(String userId) {
        String[] appid = userId.split(",");
        Boolean flag = false;
        User user = new User();
        for (int i = 0; i < appid.length; i++) {
            user.setId(appid[i]);
            flag = user.deleteById();
        }
        if (flag == true) {
            return Body.newInstance("删除成功");
        }
        return Body.newInstance("删除失败");
    }

    /**
     * 新增代理用户
     */
    @PostMapping("insertUserRole")
    public Body insertUserRole(User user, Integer proportion) {
        User user2 = new User();
        EntityWrapper<User> ew = new EntityWrapper<>();
        ew.eq("phone", user.getPhone());
        user2 = user2.selectOne(ew);
        if (user2 != null) {
            return Body.newInstance(-1, "手机号已存在！");
        }
        String filename = user.getAddress();
        String levelCode = filename.substring(filename.indexOf("省") + 1).trim();// 逗号后面
        String levelCodes = levelCode.substring(0, levelCode.indexOf("区") + 1).trim();// 逗号前面
        if (levelCodes.equals("")) {
            return Body.BODY_451;
        }
        User us = new User();
        EntityWrapper<User> ewa = new EntityWrapper<>();
        ewa.like("address", user.getAddress());
        int count = us.selectCount(ewa);
        if (count > 0) {
            return Body.newInstance(-2, "该地区已有代理");
        }
        user.setId(Hutool.getId());
        user.setTime(Hutool.parseDateToString());
        if (user.getAddress() != null) {
            user.setRole(2);
        } else {
            user.setRole(0);
        }
        user.setPassword(MD5Util.MD5EncodeUtf8(user.getPassword()));
        Boolean flag = user.insert();
        if (flag) {
            Percentage percentage = new Percentage();
            percentage.setUserId(user.getId());
            percentage.setPercentageId(Hutool.getId());
            percentage.setAddtime(Hutool.parseDateToString());
            percentage.setRegion(user.getAddress());
            percentage.setProportion(proportion);
            flag = percentage.insert();
            if (flag) {
                Dining dining = new Dining();
                EntityWrapper<Dining> dinew = new EntityWrapper<>();
                dinew.like("address", levelCodes);
                List<Dining> listdin = dining.selectList(dinew);
                for (Dining dining2 : listdin) {
                    Subordinate subordinate = new Subordinate();
                    subordinate.setSubordinateId(Hutool.getId());
                    subordinate.setAddtime(Hutool.parseDateToString());
                    subordinate.setDinId(dining2.getId());
                    subordinate.setProportion(10);
                    subordinate.setUserId(user.getId());
                    subordinate.setRegion(user.getAddress());
                    subordinate.insert();
                }
            }
            return Body.BODY_200;
        }
        return Body.BODY_500;
    }

    /**
     * 查询代理
     */
    @PostMapping("queryUserAll")
    public Body queryUserAll(User user) {
        EntityWrapper<User> ew = new EntityWrapper<>();
        if (user.getName() != null) {
            ew.like("name", user.getName());
        }
        if (user.getPhone() != null) {
            ew.like("phone", user.getPhone());
        }
        if (user.getAddress() != null) {
            ew.like("address", user.getAddress());
        }
        List<User> list = user.selectList(ew);
        Percentage percentage = new Percentage();
        EntityWrapper<Percentage> ews = new EntityWrapper<>();
        ews.orderBy("addtime", false);
        List<Percentage> lpList = percentage.selectList(ews);
        List<User> lists = new ArrayList<>();
        for (User user2 : list) {
            if (user2.getRole() == 2) {
                for (Percentage Percentage : lpList) {
                    if (Percentage.getUserId().equals(user2.getId())) {
                        user2.setProportion(Percentage.getProportion());
                    }
                    continue;
                }
                if (user2.getRole() == 2) {
                    user2.setUserRoole("代理");
                }
                lists.add(user2);
            }
            continue;
        }
        if (lists.size() > 0) {
            return Body.newInstance(lists);
        }
        return Body.BODY_500;
    }

    @PostMapping("updateUserCid")
    public Body updateUserCid(String userId, String cid) {
        User user = new User();
        user = user.selectById(userId);
        if (user != null) {
            user.setCid(cid);
            Boolean flag = user.updateById();
            if (flag) {
                return Body.BODY_200;
            }
            return Body.BODY_451;
        }
        return Body.BODY_451;
    }

    /**
     * 查询用户身份
     */
    @PostMapping("userOne")
    public Body userOne(String id) {
        User user = new User();
        user.setId(id);
        user = user.selectById();
        if (user != null) {
            EntityWrapper<Dining> ew = new EntityWrapper<>();
            ew.eq("user_id", user.getId());
            Dining dining = new Dining();
            dining = dining.selectOne(ew);
            if (dining != null) {
                user.setDinid(dining.getId());
                user.setDenglvcount(dining.getCounts());
            }
            EntityWrapper<Dining> ews = new EntityWrapper<>();
            ews.eq("user_id", user.getId());
            Riding riding = new Riding();
            riding = riding.selectOne(ews);
            if (riding != null) {
                user.setRidingId(riding.getId());
                user.setDenglvcount(riding.getCounts());
            }
            return Body.newInstance(user);
        }
        return Body.BODY_500;
    }

    /**
     * 修改代理
     */
    @PostMapping("updateAgency")
    public Body updateAgency(User user, int proportion) {
        User users = new User();
        users.setId(user.getId());
        users = users.selectById();
        if (users == null) {
            return Body.newInstance("代理不存在");
        }
        Boolean flag = user.updateById();
        if (flag) {
            Percentage percentage1 = new Percentage();
            Boolean flags = true;
            EntityWrapper<Percentage> ew = new EntityWrapper<>();
            ew.eq("user_id", user.getId());
            percentage1 = percentage1.selectOne(ew);
            if (percentage1 == null) {
                Percentage percentage = new Percentage();
                percentage.setPercentageId(Hutool.getId());
                percentage.setUserId(user.getId());
                percentage.setRegion(user.getAddress());
                percentage.setProportion(proportion);
                percentage.setAddtime(Hutool.parseDateToString());
                flags = percentage.insert();
            } else {
                percentage1.setAddtime(Hutool.parseDateToString());
                percentage1.setProportion(proportion);
                percentage1.setRegion(user.getAddress());
                flags = percentage1.updateById();
            }
            if (flags) {
                return Body.BODY_200;
            }
            return Body.BODY_500;
        }
        return Body.BODY_500;
    }

    /**
     * 查询单个代理
     */
    @PostMapping("addOne")
    public Body addOne(String id) {
        User user = new User();
        user.setId(id);
        user = user.selectById();
        if (user == null) {
            return Body.BODY_451;
        }
        Percentage percentage = new Percentage();
        EntityWrapper<Percentage> ew = new EntityWrapper<>();
        ew.eq("user_id", user.getId());
        percentage = percentage.selectOne(ew);
        if (percentage != null) {
            user.setProportion(percentage.getProportion());
            return Body.newInstance(user);
        }
        return Body.BODY_500;
    }

    /**
     * 绑定支付宝
     */
    @PostMapping("addBangDingZhiFuBao")
    public Body addBangDingZhiFuBao(String payZhifu, String payZhifu2, String userId) {
        User user = new User();
        user.setId(userId);
        user = user.selectById();
        if (user == null) {
            return Body.newInstance("用户不存在");
        }
        user.setPayZhifu(payZhifu);
        user.setPayZhifu2(payZhifu2);
        Boolean flag = user.updateById();
        if (flag) {
            return Body.newInstance("修改成功");
        }
        return Body.BODY_500;
    }

    /**
     * 我的钱包
     */
    @PostMapping("addUserMoney")
    public Body addUserMoney(String userId) {
        User user = new User();
        user.setId(userId);
        user = user.selectById();
        if (user == null) {
            return Body.newInstance("用户不存在");
        }
        return Body.newInstance(user);
    }

    /**
     * 退出登录
     */
    @PostMapping("quit")
    public Body quit(String userId) {
        User user = new User();
        user = user.selectById(userId);
        if (user != null) {
            user.setLine(0);
            Boolean falg = user.updateById();
            if (falg) {
                return Body.newInstance("退出成功");
            }
            return Body.BODY_500;
        }
        return Body.BODY_500;
    }

    /**
     * 进入商家端请求
     *
     * @param userId
     * @return
     */
    @PostMapping("updateDing")
    public Body updateDing(String userId) {
        EntityWrapper<Dining> ew = new EntityWrapper<>();
        ew.eq("user_id", userId);
        Dining dining = new Dining();
        List<Dining> list = dining.selectList(ew);
        List<Dining> lists = new ArrayList<>();
        for (Dining dining2 : list) {
            dining2.setCounts(dining2.getCounts() + 1);
            Boolean falg = dining2.updateById();
            lists.add(dining2);
        }
        if (lists.size() > 0) {
            return Body.newInstance(lists);
        }
        return Body.BODY_451;
    }

    /**
     * 进入骑手端
     *
     * @param userId
     */
    @PostMapping("updateRiding")
    public Body updateRiding(String userId) {
        Riding riding = new Riding();
        EntityWrapper<Riding> ew = new EntityWrapper<>();
        ew.eq("user_id", userId);
        List<Riding> list = riding.selectList(ew);
        List<Riding> lists = new ArrayList<>();
        for (Riding riding2 : list) {
            riding2.setCounts(riding2.getCounts() + 1);
            riding2.updateById();
            lists.add(riding2);
        }
        if (lists.size() > 0) {
            return Body.newInstance(lists);
        }
        return Body.BODY_451;
    }

    @PostMapping("addery")
    public Body addery(String id) {
        User user = new User();
        user.setId(id);
        user = user.selectById();
        if (user != null) {
            return Body.newInstance(user);
        }
        return Body.BODY_451;
    }

    @PostMapping("updateusers")
    public Body updateusers(User user) {
        MD5Util.MD5EncodeUtf8(user.getPassword());
        Boolean falg = user.updateById();
        if (falg) {
            return Body.newInstance("成功");
        }
        return Body.BODY_451;
    }

}
